#coding=utf-8
'''
Created on 2016 7 13

@author: 403720
'''
import sys
from common import check_detect_connected
sys.path.append('D:\eclipse\luyouqi\src')

import testcase.HiWifi.login_HiWiFi

import time
import ConfigParser
import common.logging_save
import common.machine_connect_wifi    #连接WIFI
import common.check_detect_connected   #检测WIFI是否连接成功
import unittest
import common.assertcheck
import shutil
import os
import testcase.HiWifi
import common.config

confir_path = common.config.Configpath
Password = "kobebyrantaaafsdfsadafsdsfdaqwrrqwbssfsadffasl"
Conf = ConfigParser.ConfigParser()
Conf.read(confir_path)
Conf.set("SSIDPASSWORD", "password", Password)
Test_write = Conf.write(open(confir_path,"w+"))

class Test(unittest.TestCase):
    def setUp(self):
        common.logging_save.logging.info("HiWiFi路由器WiFi密码即将设为超长字母：kobebyrantaaafsdfsadafsdsfdaqwrrqwbssfsadffasl")
        print time.ctime(),"HiWiFi路由器WiFi密码即将设为超长字母：kobebyrantaaafsdfsadafsdsfdaqwrrqwbssfsadffasl"

        self.Driver = testcase.HiWifi.login_HiWiFi.Login()
        self.Driver.implicitly_wait(10)
        self.Driver.find_element_by_xpath("//a[@id='set_wifi']//span[@class='icon']").click()
        time.sleep(5)
        self.Driver.switch_to_frame("Openfunc_box")
        time.sleep(1)
        self.Driver.find_element_by_id("input_password1").clear()
        time.sleep(1)
        self.Driver.find_element_by_id("input_password1").send_keys(Password)
        time.sleep(2)
        self.Driver.find_element_by_id("submit_btn").click()
        time.sleep(20)       #保存管理
        self.Driver.quit()
        common.logging_save.logging.info("HiWiFi路由器WiFi密码已经设为超长字母：kobebyrantaaafsdfsadafsdsfdaqwrrqwbssfsadffasl")
        print time.ctime(),"HiWiFi路由器WiFi密码已经设为超长字母：kobebyrantaaafsdfsadafsdsfdaqwrrqwbssfsadffasl"
        
    def tearDown(self):
        sys.path.append('\report')
        basic_path = common.config.save_report()
        print basic_path
        different = os.path.join(common.config.save_report(),'HiWifi','password_max.txt')
        shutil.copyfile(check_detect_connected.save_path,different)
        #self.Driver.quit()

    def testName(self):    #进行连接操作，然后进行判断是否连接成功，如失败则报错
        u"""测试步骤：密码设置为超长字节密码，然后WIFI设备连接路由器   期待结果：可以连接成功，如果连接失败，则直接报错"""

        self.assertEqual('success', common.assertcheck.Test(), "经过检测未连接成功，请排查问题所在")
        common.logging_save.logging.info("检测完毕，可以正常连接WIFI")
        print time.ctime(),"检测完毕，可以正常连接WIFI"

if __name__ == "__main__":
    unittest.main()
    
    